package com.jshoperxms.service.impl;

import com.jshoperxms.controller.utils.DateTools;
import com.jshoperxms.controller.utils.enums.MemberEnums;
import com.jshoperxms.dao.MemberWithdrawalsApplyTDao;
import com.jshoperxms.dao.SysMemberWithdrawalsTransferRdTDao;
import com.jshoperxms.entity.MemberWithdrawalsApplyT;
import com.jshoperxms.entity.SysMemberWithdrawalsTransferRdT;
import com.jshoperxms.service.SysMemberWithdrawalsTransferRdTService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by sdywcd on 16/11/21.
 * Des:
 */
@Service
public class SysMemberWithdrawalsTransferRdTServiceImpl extends BaseTServiceImpl<SysMemberWithdrawalsTransferRdT> implements SysMemberWithdrawalsTransferRdTService {


    @Resource
    private SysMemberWithdrawalsTransferRdTDao sysMemberWithdrawalsTransferRdTDao;


    @Resource
    private MemberWithdrawalsApplyTDao memberWithdrawalsApplyTDao;

    @Transactional(propagation= Propagation.REQUIRED)
    @Override
    public void updateSysDrawalsTrasnferRdThenUpdateMemberWithDrawalsTransactional(SysMemberWithdrawalsTransferRdT rq) {
        //1,查询系统转账的记录并更新
        if(StringUtils.isNotBlank(rq.getId())){
            SysMemberWithdrawalsTransferRdT bean=this.sysMemberWithdrawalsTransferRdTDao.findByPK(SysMemberWithdrawalsTransferRdT.class,rq.getId());
            if(bean!=null){
                bean.setTransferpaytime(DateTools.getSystemTimeBi());
                bean.setTransfermoney(rq.getTransfermoney());
                bean.setUpdatetime(DateTools.getSystemTimeBi());
                bean.setTransferstatus(rq.getTransferstatus());
                bean.setTradeid(rq.getTradeid());
                bean.setNote(rq.getNote());
                bean.setVersiont(bean.getVersiont()+1);
                this.sysMemberWithdrawalsTransferRdTDao.update(bean);
            }

            //2,更新会员提现状态
            MemberWithdrawalsApplyT memberWithdrawalsApplyT=this.memberWithdrawalsApplyTDao.findByPK(MemberWithdrawalsApplyT.class,bean.getMemberwithdrawalsid());
            memberWithdrawalsApplyT.setIstransfer(rq.getTransferstatus());
            memberWithdrawalsApplyT.setUpdatetime(DateTools.getSystemTimeBi());
            this.memberWithdrawalsApplyTDao.update(memberWithdrawalsApplyT);
        }
    }
}
